package com.hjc.answer.controller;

import com.hjc.answer.model.StatisticsProj;
import com.hjc.answer.service.impl.StatisticsServiceImpl;
import com.hjc.answer.tools.GsonTools;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: HJC
 * Date: 2019/11/17
 * Time: 20:08
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/statistics")
public class StatisticsCtl {
    @Autowired
    private StatisticsServiceImpl statisticsService;

    @RequestMapping( value = "statisInsert" ,method = RequestMethod.POST,produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String statis(StatisticsProj statisticsProj){
        if(statisticsProj != null){
            System.out.println(statisticsProj.toString());
        }
        int count = statisticsService.statisInsert(statisticsProj);
        System.out.println(count);
        return GsonTools.getGsonTools().tojsons(count);
    }
    //查看答题记录
    @RequestMapping("oldStatis")
    public String oldStatis(){

        return "questionFloor";
    }
    //queryAllStatistics
    @RequestMapping(value = "queryStatis" , method = RequestMethod.POST , produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String queryStatis(){
        List<StatisticsProj> querystatis = statisticsService.queryStatic();
        return GsonTools.getGsonTools().tojsons(querystatis);
    }

    @RequestMapping(value = "queryStatisById" , method = RequestMethod.POST , produces = "text/json;charset=UTF-8")
    @ResponseBody
    public String queryStatisById(String uid){
        List<StatisticsProj> querystatis = statisticsService.queryStaticById(uid);

        return GsonTools.getGsonTools().tojsons(querystatis);
    }

}
